﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace odinshrine
{
    class Options:Menu
    {
        static GestionPhysics phys = new GestionPhysics();
        public static Texture2D menuPrincipal, boutonCommandes, retour, fond_options, sonBouton;
        public static Rectangle commandesRect, menuRect, sonRect;
        public static int commandesX = 450, commandesY = 200, menuX = 450, menuY = 400, sonX = 450, sonY = 300;
        public static int placeOptions = 0;

        /*private static void GestionSouris(int mouseX, int mouseY, MouseState mouse)
        {
            //Menu Options
            if (timer_souris.Milliseconds > delaiSouris)
            {
                if (mouse.LeftButton == ButtonState.Pressed)
                {
                    timer_souris = TimeSpan.Zero;

                    if (mainMenuSouris(mouseX, mouseY))
                    {
                        menu_options = false;
                        //On met les rectangles du menu sur lequel on arrive a leurs places, on vire les autres
                        Mainmenu.quitterRect.X = Mainmenu.quitterX;
                        Mainmenu.quitterRect.Y = Mainmenu.quitterY;
                        Mainmenu.jouerRect.X = Mainmenu.jouerX;
                        Mainmenu.jouerRect.Y = Mainmenu.jouerY;
                        Mainmenu.optionsRect.X = Mainmenu.optionsX;
                        Mainmenu.optionsRect.Y = Mainmenu.optionsY;
                        commandesRect.X = -1000;
                        menuRect.X = -1000;
                    }
                    if (CommandesSouris(mouseX, mouseY))
                    {
                        menu_commandes = true;
                        Commandes.ecrire = false;
                        Commandes.position = 0;
                        commandesRect.X = -1000;
                        menuRect.X = -1000;
                    }
                    if (sonSouris(mouseX, mouseY))
                    {
                        menu_son = true;
                        commandesRect.X = -1000;
                        menuRect.X = -1000;
                        sonRect.X = -1000;
                        MenuSon.bouton1Rect.X = MenuSon.bouton1X;
                        MenuSon.bouton2Rect.X = MenuSon.bouton2X;
                        MenuSon.Sonretour.X = MenuSon.SonretourX;
                    }
                }
            }
        }*/

        private static void gestionClavier(KeyboardState clavier, int mouseX, int mouseY)
        {
            if (menu_options && !Menu.menu_commandes)
            {
                //Pour gerer le "timerbouton"
                if (clavier.IsKeyUp(Keys.Down))
                {
                    Mainmenu.clavierUpdown = true;
                }
                if (clavier.IsKeyUp(Keys.Up))
                {
                    Mainmenu.clavierUpup = true;
                }

                if (clavier.IsKeyDown(Keys.Down) && placeOptions != 3 && Mainmenu.clavierUpdown)
                {
                    placeOptions++;
                    Mainmenu.clavierUpdown = false;
                }
                if (clavier.IsKeyDown(Keys.Up) && placeOptions != 1 && Mainmenu.clavierUpup)
                {
                    placeOptions--;
                    Mainmenu.clavierUpup = false;
                }
            }

            //Menu Options
            if (placeOptions == 3 && clavier.IsKeyDown(Keys.Enter))
            {
                menu_options = false;
                //On met les rectangles du menu sur lequel on arrive a leurs places, on vire les autres
                Mainmenu.quitterRect.X = Mainmenu.quitterX;
                Mainmenu.quitterRect.Y = Mainmenu.quitterY;
                Mainmenu.jouerRect.X = Mainmenu.jouerX;
                Mainmenu.jouerRect.Y = Mainmenu.jouerY;
                Mainmenu.optionsRect.X = Mainmenu.optionsX;
                Mainmenu.optionsRect.Y = Mainmenu.optionsY;
                commandesRect.X = -1000;
                menuRect.X = -1000;
                sonRect.X = -1000;
            }

            if (placeOptions == 2 && clavier.IsKeyDown(Keys.Enter))
            {
                menu_son = true;
                commandesRect.X = -1000;
                menuRect.X = -1000;
                sonRect.X = -1000;
                MenuSon.Sonretour.X = MenuSon.SonretourX;
                MenuSon.bouton1Rect.X = MenuSon.bouton1X;
                MenuSon.bouton2Rect.X = MenuSon.bouton2X;
            }

            if (placeOptions == 1 && clavier.IsKeyDown(Keys.Enter))
            {
                menu_commandes = true;
                Commandes.ecrire = false;
                Commandes.position = 0;
                commandesRect.X = -1000;
                menuRect.X = -1000;
            }
        }

        public static void Gestion(KeyboardState clavier, int mouseX, int mouseY, MouseState mouse)
        {
            gestionClavier(clavier, mouseX, mouseY);
        }

        //Initialise le menu Options
        public static void initOptions(ContentManager Content)
        {
            boutonCommandes = Content.Load<Texture2D>("Menu/commandes");
            retour = Content.Load<Texture2D>("Menu/retour");
            menuPrincipal = Content.Load<Texture2D>("Menu/retour");
            sonBouton = Content.Load<Texture2D>("Menu/sons");
            fond_options = Content.Load<Texture2D>("Menu/menu");

            commandesRect = new Rectangle(-1000, commandesY, boutonCommandes.Width, boutonCommandes.Height);
            menuRect = new Rectangle(-1000, menuY, menuPrincipal.Width, menuPrincipal.Height);
            sonRect = new Rectangle(-1000, sonY, sonBouton.Width, sonBouton.Height);
        }

        //Dessine le menu Options
        public static void drawOptions(SpriteBatch spriteBatch, int mouseX, int mouseY)
        {
            spriteBatch.Draw(fond_options, new Vector2(0, 0), Color.White);
            spriteBatch.Draw(boutonCommandes, new Vector2(commandesX, commandesY), Color.White);
            spriteBatch.Draw(menuPrincipal, new Vector2(menuX, menuY), Color.White);
            spriteBatch.Draw(sonBouton, new Vector2(sonX, sonY), Color.White);
            if (placeOptions == 1)
            {
                spriteBatch.Draw(Mainmenu.imgBouton, new Vector2(commandesX - 70, commandesY), Color.White);
            }
            if (placeOptions == 2)
            {
                spriteBatch.Draw(Mainmenu.imgBouton, new Vector2(sonX - 70, sonY), Color.White);
            }
            if (placeOptions == 3)
            {
                spriteBatch.Draw(Mainmenu.imgBouton, new Vector2(menuX - 70, menuY), Color.White);
            }
        }

        /*private static bool sourisOptions(int x, int y)
        {
            return (CommandesSouris(x, y) || mainMenuSouris(x, y));
        }

        //Pour retourner au menu
        private static bool mainMenuSouris(int x, int y)
        {
            return (phys.collisionRectangleRectangle(new Rectangle(x, y, 1, 1), menuRect));
        }
        private static bool sonSouris(int x, int y)
        {
            return (phys.collisionRectangleRectangle(new Rectangle(x, y, 1, 1), sonRect));
        }
        private static bool CommandesSouris(int x, int y)
        {
            return (phys.collisionRectangleRectangle(new Rectangle(x, y, 1, 1), commandesRect));
        }*/
    }
}
